package com.controller;

import com.controller.vo.ResultVO;
import com.dto.LotteryRecordWithPrizeDto;
import com.entity.LotteryDrawRecord;
import com.github.pagehelper.PageInfo;
import com.service.LotteryDrawRecordService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName LotteryDrawRecordController
 * @Description TODO
 * @Author Kx
 * @Date 2025/6/18 16:40
 * @Version 1.0
 */
@RestController
@RequestMapping("/lotteryDrawRecord")
public class LotteryDrawRecordController extends BaseController{
    private final LotteryDrawRecordService lotteryDrawRecordService;

    public LotteryDrawRecordController(LotteryDrawRecordService lotteryDrawRecordService) {
        this.lotteryDrawRecordService = lotteryDrawRecordService;
    }

    /**
     * @author: kx
     * @date: 2025/6/18 16:45
     * @param lotteryDrawRecords : 奖品记录列表
     * @param address : 收货地址
     * @return com.controller.vo.ResultVO<java.lang.String>
     * @description: 添加奖品记录
    */
    @PostMapping("/addLotteryDrawRecord")
    public ResultVO<String> addLotteryDrawRecord(@RequestBody List<LotteryDrawRecord> lotteryDrawRecords, @RequestParam(value = "address", required = false) String address) {
        lotteryDrawRecordService.addLotteryDrawRecord(lotteryDrawRecords, address);
        return success("添加抽奖记录成功");
    }

    /**
     * @author: kx
     * @date: 2025/6/18 20:09
     * @param userId : 用户id
     * @return com.controller.vo.ResultVO<java.util.List<com.dto.LotteryRecordWithPrizeDto>>
     * @description: 根据用户id查询该用户的抽奖信息
    */
    @GetMapping("/findByUserId")
    public ResultVO<List<LotteryRecordWithPrizeDto>> findByUserId(@RequestParam("userId") Integer userId) {
       return success(lotteryDrawRecordService.findByUserId(userId));
    }

    /**
     * @author: kx
     * @date: 2025/6/18 20:27
     * @param pageNum : 页码
     * @param pageSize : 每页数量
     * @return com.controller.vo.ResultVO<com.github.pagehelper.PageInfo<com.entity.LotteryDrawRecord>>
     * @description: 分页查询所有抽奖记录
    */
    @GetMapping("/findPagedAllRecords")
    public ResultVO<PageInfo<LotteryRecordWithPrizeDto>> findPagedAllRecords(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return success(lotteryDrawRecordService.findPagedAllRecords(pageNum, pageSize));
    }

    /**
     * @author: kx
     * @date: 2025/6/19 11:06
     * @param keyword : 关键字
     * @param pageNum : 页码
     * @param pageSize : 每页数量
     * @return com.controller.vo.ResultVO<com.github.pagehelper.PageInfo<com.dto.LotteryRecordWithPrizeDto>>
     * @description: 根据用户名称模糊分页查询抽奖记录
    */
    @GetMapping("/findRecordsByKeyword")
    public ResultVO<PageInfo<LotteryRecordWithPrizeDto>> findRecordsByKeyword(@RequestParam("keyword") String keyword, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return success(lotteryDrawRecordService.findRecordsByKeyword(keyword, pageNum, pageSize));
    }
}
